﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace UI.Dialogs.Dictionaries
{
    /// <summary>
    /// Basic dictionary form
    /// </summary>
    public partial class DictionaryFormBase : Window
    {
        /// <summary>
        /// Occurs when [new dictionary item added].
        /// </summary>
        public event EventHandler<RoutedEventArgs> AddClicked;
        /// <summary>
        /// Occurs when [existing dictionary item updated].
        /// </summary>
        public event EventHandler<RoutedEventArgs> SaveClicked;
        /// <summary>
        /// Called when [new dictionary item added].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        protected void OnAddClicked(object sender, RoutedEventArgs e)
        {
            if(AddClicked != null)
            {
                AddClicked(sender, e);
            }
        }

        /// <summary>
        /// Called when [existing dictionary item updated].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        protected void OnSaveClicked(object sender, RoutedEventArgs e)
        {
            if(SaveClicked != null)
            {
                SaveClicked(sender, e);
            }
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="DictionaryFormBase"/> class.
        /// </summary>
        public DictionaryFormBase()
        {
            InitializeComponent();

            EditTab.IsEnabled = false;
            SetAddDefault();
        }

        /// <summary>
        /// Gets or sets the grid control.
        /// </summary>
        /// <value>The grid control.</value>
        public UserControl GridControl
        {
            get
            {
                return GridRegion.Content as UserControl;
            }
            set
            {
                GridRegion.Content = value;
            }
        }

        /// <summary>
        /// Gets or sets the edit control.
        /// </summary>
        /// <value>The edit control.</value>
        public UserControl EditControl
        {
            get
            {
                return EditRegion.Content as UserControl;
            }
            set
            {
                EditRegion.Content = value;
            }
        }

        /// <summary>
        /// Gets or sets the add control.
        /// </summary>
        /// <value>The add control.</value>
        public UserControl AddControl
        {
            get
            {
                return AddRegion.Content as UserControl;
            }
            set
            {
                AddRegion.Content = value;
            }
        }

        /// <summary>
        /// Handles the Click event of the EditPub control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void EditPub_Click(object sender, RoutedEventArgs e)
        {
            OnSaveClicked(sender, e);
        }

        /// <summary>
        /// Handles the Click event of the AddPub control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void AddPub_Click(object sender, RoutedEventArgs e)
        {
            OnAddClicked(sender, e);
        }

        /// <summary>
        /// Sets the Add tab as default.
        /// </summary>
        public void SetAddDefault()
        {
            AddTab.IsSelected = true;
        }

        /// <summary>
        /// Sets the Edit tab as default.
        /// </summary>
        public void SetEditDefault()
        {
            EditTab.IsSelected = true;
        }


    }
}